﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FAQFrameworks;
using FooFun.DataElements.Dtos;

namespace FooFun.Web.Controls
{
    public class ReplyCountForUser : DataElementControl
    {
        Guid userId;

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            userId = FAQContext.Current.AccountId;
            if (userId != Guid.Empty)
            {
                this.DataElement = new ReplyCountDataElement();
            }
            else
            {
                this.DataElement = new EmptyDataElement();
            }
        }

        public class ReplyCountDataElement : DataElement
        {
            public override bool IsEmpty
            {
                get
                {
                    return false;
                }
            }

            public override IDataElement this[string key]
            {
                get
                {
                    Guid userId = FAQContext.Current.AccountId;
                    switch (key)
                    {
                        case "ReplyCount":
                            int replyCount = topicManager.CountRelpyForUser(userId);
                            return new IntDataElement(replyCount);
                        case "TopReplyCount":
                            int topReplyCount = topicManager.CountTopReplyForUser(userId);
                            return new IntDataElement(topReplyCount);
                        default:
                            break;
                    }
                    return base[key];
                }
                set
                {
                    base[key] = value;
                }
            }

            TopicManager topicManager;

            public ReplyCountDataElement()
            {
                topicManager = new TopicManager();
            }
        }
    }
}
